<?php
namespace App\V3\V3_2_7\Models;

use Illuminate\Database\Eloquent\Model;
use DateTimeInterface;

class CloudDeviceModel extends Model
{

    public static $_DEVICE_STATUS_1 = 1;//审核通过
    public static $_DEVICE_STATUS_2 = 2;//待审核
    public static $_DEVICE_STATUS_LIST = [1=>'通过',2=>'不通过'];

    protected $table        = 'cloud_device'; //表名
    protected $primaryKey   = 'cd_id'; //表主键
    protected $dateFormat   = 'U';//这个时间字段被为被格式化为UNIX 时间戳的形式存储
    //toArray 时间转换问题
    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    /**
     * 是否审核通过
     */
    public function isCheckPass()
    {
        if($this->device_status == 1){
            return true;
        }else{
            return false;
        }
    }

    /**
     * 是否在线，表示可用
     */
    public function isOnLine()
    {
        if($this->device_action_status == 'up'){
            return true;
        }else{
            return false;
        }
    }

    //toArray 时间转换问题
    public static function getAccountInfo(int $userId)
    {
        return self::where('id', $userId)->first();
    }

}
